<?php

/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/3/31
 * Time: 上午11:58
 */

if (!function_exists('getClient_id')) {

    /**
     * 获取客户端ID
     * @param null $_ip
     * @return null
     */
    function getClient_id($_ip = null)
    {
        if (isset($_SERVER['HTTP_CLIENT_IP'])
            || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
            || isset($_SERVER['REMOTE_ADDR'])
        ) {
            if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
                //check ip from share internet
                $_ip = $_SERVER['HTTP_CLIENT_IP'];
            } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                //to check ip is pass from PRoxy
                $_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            } else {
                $_ip = $_SERVER['REMOTE_ADDR'];
            }

        }

        return $_ip;
    }

}
